//
//  XMLParser.m
//  BateauGenerique
//
//  Created by Florent Champigny on 23/05/2014.
//  Copyright (c) 2014 Kevin De Jesus Ferreira. All rights reserved.
//

#import "XMLParser.h"
#import "RBGColorManager.h"
#import "Constantes.h"
#import "RBGAppDelegate.h"

@implementation XMLParser{
    TBXML* tbxml;
}

-(id)initWithString:(NSString*)xml
{
	if(self =[self init])
		tbxml = [[TBXML alloc]initWithXMLString:xml error:nil];
	return(self);
}

-(id)parse:(TBXMLElement*)element
{
    if (element){
        if([[TBXML elementName:element] isEqualToString:@"actu"])
            return [self parseActualite:element];
        else if([[TBXML elementName:element] isEqualToString:@"ad"])
            return [self parseAnnonce:element];
        else if([[TBXML elementName:element] isEqualToString:@"detail"])
            return [self parseAnnonce:element];
        else if([[TBXML elementName:element] isEqualToString:@"parametres"])
            return [self parseParametres:element];
        else if([[TBXML elementName:element] isEqualToString:@"client"])
            return [self parseClient:element];
        else if([[TBXML elementName:element] isEqualToString:@"nbann"])
            return [self parseNb:element];
        else
            return [self parseListe:element];
    }
    return nil;
}

-(id)parse
{
    TBXMLElement * root = tbxml.rootXMLElement;
	if (root){
        return [self parse:root];
    }
    return nil;
}

-(id)parseListe{
    TBXMLElement * root = tbxml.rootXMLElement;
	if (root)
        return [self parseListe:root];
    return nil;
}

-(id)parseListe:(TBXMLElement*)element
{
    NSMutableArray *liste = [NSMutableArray array];
    
    if([[TBXML elementName:element] isEqualToString:@"actus_client"]){
        TBXMLElement * e = [TBXML childElementNamed:@"actu" parentElement:element];
        while (e !=nil)
        {
            [liste addObject:[self parseActualite:e]];
            e = [TBXML nextSiblingNamed:@"actu" searchFromElement:e];
        }
    }
    
    else if([[TBXML elementName:element] isEqualToString:@"resultat"]){
        
        TBXMLElement * e_nb_result = [TBXML childElementNamed:@"nb_result" parentElement:element];
        ((RBGAppDelegate *)[[UIApplication sharedApplication] delegate]).number = [TBXML textForElement:e_nb_result];
        
        TBXMLElement * e_ads = [TBXML childElementNamed:@"ads" parentElement:element];
        
        TBXMLElement * e = [TBXML childElementNamed:@"ad" parentElement:e_ads];
        while (e !=nil)
        {
            [liste addObject:[self parseAnnonce:e]];
            e = [TBXML nextSiblingNamed:@"ad" searchFromElement:e];
        }
    }
    
    else if([[TBXML elementName:element] isEqualToString:@"marque_bateau"]){
        return [self parseMarques:element];
    }
    else if([[TBXML elementName:element] isEqualToString:@"marque_moteur"]){
        return [self parseMarques:element];
    }
    
    else if([[TBXML elementName:element] isEqualToString:@"menu_client"]){
        return [self parseTypeAnnonces:element];
    }
    
    else if([[TBXML elementName:element] isEqualToString:@"categories"]){
        return [self parseCategories:element];
    }
    
    else if([[TBXML elementName:element] isEqualToString:@"regions"]){
        return [self parseRegions:element];
    }
    
    else if([[TBXML elementName:element] isEqualToString:@"lieux"]){
        return [self parseLieux:element];
    }
    
    else if([[TBXML elementName:element] isEqualToString:@"etats"]){
        return [self parseEtat:element];
    }
    
    else if([[TBXML elementName:element] isEqualToString:@"departements"]){
        return [self parseDepartements:element];
    }
    
    else if([[TBXML elementName:element] isEqualToString:@"energies"]){
        return [self parseEnergies:element];
    }
    
    else if([[TBXML elementName:element] isEqualToString:@"energies"]){
        return [self parseEnergies:element];
    }
    
    else if([[TBXML elementName:element] isEqualToString:@"services"]){
        return [self parseServices:element];
    }
    else if([[TBXML elementName:element] isEqualToString:@"modele_bateau"]){
        return [self parseModeles:element];
    }
    
    else if([[TBXML elementName:element] isEqualToString:@"favoris"]){
        {
            TBXMLElement * e_ads = [TBXML childElementNamed:@"bateaux" parentElement:element];
            
            TBXMLElement * e = [TBXML childElementNamed:@"ad" parentElement:e_ads];
            while (e !=nil)
            {
                [liste addObject:[self parseAnnonce:e]];
                e = [TBXML nextSiblingNamed:@"ad" searchFromElement:e];
            }
        }
        {
            TBXMLElement * e_ads = [TBXML childElementNamed:@"moteurs" parentElement:element];
            
            TBXMLElement * e = [TBXML childElementNamed:@"ad" parentElement:e_ads];
            while (e !=nil)
            {
                [liste addObject:[self parseAnnonce:e]];
                e = [TBXML nextSiblingNamed:@"ad" searchFromElement:e];
            }
        }
        {
            TBXMLElement * e_ads = [TBXML childElementNamed:@"divers" parentElement:element];
            
            TBXMLElement * e = [TBXML childElementNamed:@"ad" parentElement:e_ads];
            while (e !=nil)
            {
                [liste addObject:[self parseAnnonce:e]];
                e = [TBXML nextSiblingNamed:@"ad" searchFromElement:e];
            }
        }
        {
            TBXMLElement * e_ads = [TBXML childElementNamed:@"locations" parentElement:element];
            
            TBXMLElement * e = [TBXML childElementNamed:@"ad" parentElement:e_ads];
            while (e !=nil)
            {
                [liste addObject:[self parseAnnonce:e]];
                e = [TBXML nextSiblingNamed:@"ad" searchFromElement:e];
            }
        }
        
    }
    
    
    
    return liste;
}

-(id)parseActualite:(TBXMLElement*)parent
{
    Actualite* actualite = [[Actualite alloc] init];
    TBXMLElement * e;
    
    e = [TBXML childElementNamed:@"id" parentElement:parent];
    actualite.id = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"title" parentElement:parent];
    actualite.title = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"titre" parentElement:parent];
    if(e != nil)
        actualite.title = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"link" parentElement:parent];
    actualite.link = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"image" parentElement:parent];
    actualite.imageAdress = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"img" parentElement:parent];
    actualite.imageAdress = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"date" parentElement:parent];
	actualite.dateFormattee = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"pubDate" parentElement:parent];
	actualite.pubDate = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"description" parentElement:parent];
	actualite.description = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"texte" parentElement:parent];
    actualite.description = [TBXML textForElement:e];
    
    return actualite;
}

-(id)parseAnnonce:(TBXMLElement*)parent
{
    Annonce* annonce = [[Annonce alloc] init];
    
    TBXMLElement * e;
    
    e = [TBXML childElementNamed:@"id" parentElement:parent];
    annonce.numero = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"title" parentElement:parent];
	annonce.title = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"moteur" parentElement:parent];
    annonce.nomMoteur = [TBXML textForElement:e];
    
    if(e != nil){
        
        Moteur *moteur = [[Moteur alloc] init];
        
        TBXMLElement *f;
        
        f = [TBXML childElementNamed:@"info_moteur" parentElement:e];
        moteur.infoMoteur = [TBXML textForElement:f];
        
        f = [TBXML childElementNamed:@"propulsion" parentElement:e];
        moteur.propulsion = [TBXML textForElement:f];
        
        f = [TBXML childElementNamed:@"heure_moteur" parentElement:e];
        moteur.heureMoteur = [TBXML textForElement:f];
        
        f = [TBXML childElementNamed:@"annee_moteur" parentElement:e];
        moteur.anneeMoteur = [TBXML textForElement:f];
        
        f = [TBXML childElementNamed:@"marque_moteur" parentElement:e];
        moteur.marqueMoteur = [TBXML textForElement:f];
        
        f = [TBXML childElementNamed:@"puissance_moteur" parentElement:e];
        moteur.puissanceMoteur = [TBXML textForElement:f];
        
        annonce.moteur = moteur;
    }
    
	
    
    
    //GERER MOTEUR
    
    e = [TBXML childElementNamed:@"longueur" parentElement:parent];
	annonce.longueur = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"annee" parentElement:parent];
	annonce.annee = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"categorie" parentElement:parent];
	annonce.categorie = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"gpslatitude" parentElement:parent];
	annonce.gpsLatitude = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"gpslongitude" parentElement:parent];
	annonce.gpsLongtitude = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"type" parentElement:parent];
	annonce.type = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"idclient" parentElement:parent];
	annonce.idClient = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"logo" parentElement:parent];
	annonce.logoVendeur = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"typeclient" parentElement:parent];
	annonce.typeClient = [TBXML textForElement:e];
    
    NSMutableArray *photos = [NSMutableArray array];
    
    e = [TBXML childElementNamed:@"photos" parentElement:parent];
    if(e != NULL)
    {
        TBXMLElement * f = [TBXML childElementNamed:@"enclosure" parentElement:e];
        while (f !=nil)
        {
            Lien *lien = [[Lien alloc] init];
            
            lien.type = [TBXML valueOfAttributeNamed:@"type" forElement:f];
            lien.url = [TBXML valueOfAttributeNamed:@"url" forElement:f];
            
            [photos addObject:lien];
            
            f = [TBXML nextSiblingNamed:@"enclosure" searchFromElement:f];
        }
    }
    annonce.photos = photos;
    
    e = [TBXML childElementNamed:@"enclosure" parentElement:parent];
    if(e != NULL)
    {
        Lien *lien = [[Lien alloc] init];
        
        lien.type = [TBXML valueOfAttributeNamed:@"type" forElement:e];
        lien.url = [TBXML valueOfAttributeNamed:@"url" forElement:e];
        
        if([lien.type isEqualToString:@"image/jpeg"])
           [annonce.photos addObject:lien];
        
        
        annonce.lien = lien;
    }
    
    e = [TBXML childElementNamed:@"prix" parentElement:parent];
	annonce.prix = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"taxeprix" parentElement:parent];
	annonce.taxePrix = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"pubDate" parentElement:parent];
	annonce.pubDate = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"lien_annonce" parentElement:parent];
	annonce.lienAnnonce = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"numero_vendeur" parentElement:parent];
	annonce.numeroVendeur = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"etat" parentElement:parent];
	annonce.etat = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"largeur" parentElement:parent];
	annonce.largeur = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"nb_cabine" parentElement:parent];
	annonce.nbCabines = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"nb_couch" parentElement:parent];
	annonce.nbCouchettes = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"nb_sdb" parentElement:parent];
	annonce.nbSallesDeBain = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"garantie" parentElement:parent];
	annonce.garantie = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"commentaire" parentElement:parent];
	annonce.commentaire = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"place_de_port" parentElement:parent];
	annonce.placeDePort = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"taxe" parentElement:parent];
	annonce.taxe = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"equipements" parentElement:parent];
    {
        NSMutableArray *equipements = [NSMutableArray array];
        TBXMLElement * f = [TBXML childElementNamed:@"equipement" parentElement:e];
        while (f !=nil)
        {
            [equipements addObject:[TBXML textForElement:f]];
            f = [TBXML nextSiblingNamed:@"equipement" searchFromElement:e];
        }
        annonce.equipement = equipements;
    }
    
    e = [TBXML childElementNamed:@"electroniques" parentElement:parent];
    {
        NSMutableArray *electroniques = [NSMutableArray array];
        TBXMLElement * f = [TBXML childElementNamed:@"electronique" parentElement:e];
        while (f !=nil)
        {
            [electroniques addObject:[TBXML textForElement:f]];
            f = [TBXML nextSiblingNamed:@"electronique" searchFromElement:e];
        }
        annonce.electroniques = electroniques;
    }
    
    e = [TBXML childElementNamed:@"nb_photos" parentElement:parent];
	annonce.nbPhotos = [TBXML textForElement:e];
    
    /*
    e = [TBXML childElementNamed:@"photos" parentElement:parent];
    if(e != nil)
    {
        NSMutableArray *photos = [NSMutableArray array];
        TBXMLElement * f = [TBXML childElementNamed:@"enclosure" parentElement:e];
        while (f !=nil)
        {
            Lien *lien = [[Lien alloc] init];
            
            lien.type = [TBXML valueOfAttributeNamed:@"type" forElement:f];
            lien.url = [TBXML valueOfAttributeNamed:@"url" forElement:f];
            
            [photos addObject:lien];
            
            f = [TBXML nextSiblingNamed:@"enclosure" searchFromElement:e];
            
        }
        if(annonce.photos != nil)
            [annonce.photos addObjectsFromArray:photos];
        else
            annonce.photos = photos;
    }*/
    
    e = [TBXML childElementNamed:@"vendeur" parentElement:parent];
    {
        Vendeur *vendeur = [[Vendeur alloc] init];
        
        TBXMLElement * f;
        
        f = [TBXML childElementNamed:@"nom" parentElement:e];
        vendeur.nom = [TBXML textForElement:f];
        
        f = [TBXML childElementNamed:@"numero" parentElement:e];
        vendeur.numero = [TBXML textForElement:f];
        
        f = [TBXML childElementNamed:@"id" parentElement:e];
        if(f != nil)
            vendeur.numero = [TBXML textForElement:f];
        
        f = [TBXML childElementNamed:@"logo" parentElement:e];
        vendeur.logo = [TBXML textForElement:f];
        
        f = [TBXML childElementNamed:@"email" parentElement:e];
        vendeur.email = [TBXML textForElement:f];
        
        f = [TBXML childElementNamed:@"adresse" parentElement:e];
        vendeur.adresse = [TBXML textForElement:f];
        
        f = [TBXML childElementNamed:@"cp" parentElement:e];
        vendeur.codePostal = [TBXML textForElement:f];
        
        f = [TBXML childElementNamed:@"latitude" parentElement:e];
        vendeur.gpsLatitude = [TBXML textForElement:f];
        
        f = [TBXML childElementNamed:@"longitude" parentElement:e];
        vendeur.gpsLongitude = [TBXML textForElement:f];
        
        f = [TBXML childElementNamed:@"ville" parentElement:e];
        vendeur.ville = [TBXML textForElement:f];
        
        f = [TBXML childElementNamed:@"tel1" parentElement:e];
        vendeur.tel1 = [TBXML textForElement:f];
        
        f = [TBXML childElementNamed:@"tel2" parentElement:e];
        vendeur.tel2 = [TBXML textForElement:f];
        
        f = [TBXML childElementNamed:@"type" parentElement:e];
        vendeur.type = [TBXML textForElement:f];
        
        f = [TBXML childElementNamed:@"siteweb" parentElement:e];
        vendeur.siteWeb = [TBXML textForElement:f];
        
        
        annonce.vendeur = vendeur;
    }
    
    e = [TBXML childElementNamed:@"apartirde" parentElement:parent];
	annonce.apartirDe = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"port_de_depart" parentElement:parent];
	annonce.portDeDepart = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"lieu_nav" parentElement:parent];
	annonce.lieuNav = [TBXML textForElement:e];
    
    
    return annonce;
}

-(id)parseCategories:(TBXMLElement*)element
{
    NSMutableArray *categories = [NSMutableArray array];
    TBXMLElement * f = [TBXML childElementNamed:@"categorie" parentElement:element];
    while (f !=nil)
    {
        Categorie* categorie = [[Categorie alloc] init];
        
        categorie.id = [TBXML valueOfAttributeNamed:@"id" forElement:f];
        categorie.libelle = [TBXML textForElement:f];
        
        [categories addObject:categorie];
        f = [TBXML nextSiblingNamed:@"categorie" searchFromElement:f];
    }
    return categories;
}

-(id)parseClient:(TBXMLElement*)element
{
    Client* client = [[Client alloc] init];
    
    TBXMLElement * e;
    
    e = [TBXML childElementNamed:@"id" parentElement:element];
    client.id = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"contrat" parentElement:element];
    client.contrat = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"nom" parentElement:element];
    client.nom = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"adresse" parentElement:element];
    client.adresse = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"cp" parentElement:element];
    client.cp = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"ville" parentElement:element];
    client.ville = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"tel1" parentElement:element];
    client.tel1 = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"tel2" parentElement:element];
    client.tel2 = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"fax" parentElement:element];
    client.fax = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"email" parentElement:element];
    client.email = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"contact" parentElement:element];
    client.contact = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"ville" parentElement:element];
    client.departement = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"cp" parentElement:element];
    client.departementNum = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"image" parentElement:element];
    client.image = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"horaires" parentElement:element];
    client.horaires = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"services" parentElement:element];
    client.services = [self parseServices:e];
    
    e = [TBXML childElementNamed:@"distributeur" parentElement:element];
    client.distributeur = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"gpslatitude" parentElement:element];
    client.lat = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"gpslongitude" parentElement:element];
    client.lng = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"siteweb" parentElement:element];
    client.siteWeb = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"description" parentElement:element];
    client.description = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"logo" parentElement:element];
    client.logo = [TBXML valueOfAttributeNamed:@"url" forElement:e];
    
    e = [TBXML childElementNamed:@"nb_bateau" parentElement:element];
    client.nbBateau = [[TBXML textForElement:e] intValue];
    
    e = [TBXML childElementNamed:@"nb_moteur" parentElement:element];
    client.nbMoteur = [[TBXML textForElement:e] intValue];
    
    e = [TBXML childElementNamed:@"nb_accessoires" parentElement:element];
    client.nbAccessoires = [[TBXML textForElement:e] intValue];
    
    e = [TBXML childElementNamed:@"nom" parentElement:element];
    client.nom = [TBXML textForElement:e];
    
    
    return client;
}

-(id)parseDepartements:(TBXMLElement*)element
{
    NSMutableArray *departements = [NSMutableArray array];
    TBXMLElement * f = [TBXML childElementNamed:@"departement" parentElement:element];
    
    while (f !=nil)
    {
        
        Departement* departement = [[Departement alloc] init];
        
        departement.id = [TBXML valueOfAttributeNamed:@"id" forElement:f];
        departement.nom = [TBXML textForElement:f];
        
        
        [departements addObject:departement];
        f = [TBXML nextSiblingNamed:@"departement" searchFromElement:f];
    }
    
    return departements;
}

-(id)parseEnergies:(TBXMLElement*)element
{
    NSMutableArray *array = [NSMutableArray array];
    TBXMLElement * f = [TBXML childElementNamed:@"energie" parentElement:element];
    while (f !=nil)
    {
        
        Energie* energie = [[Energie alloc] init];
        
        energie.id = [TBXML valueOfAttributeNamed:@"id" forElement:f];
        energie.nom = [TBXML textForElement:element];
        
        
        [array addObject:energie];
        f = [TBXML nextSiblingNamed:@"energie" searchFromElement:f];
    }
    
    return array;
}

-(id)parseEtat:(TBXMLElement*)element
{
    NSMutableArray *array = [NSMutableArray array];
    TBXMLElement * f = [TBXML childElementNamed:@"etat" parentElement:element];
    while (f !=nil)
    {
        
        Etat* etat = [[Etat alloc] init];
        
        etat.id = [TBXML valueOfAttributeNamed:@"id" forElement:f];
        etat.nomEtat = [TBXML textForElement:f];
        
        
        [array addObject:etat];
        f = [TBXML nextSiblingNamed:@"etat" searchFromElement:f];
    }
    
    return array;
}


-(id)parseLieux:(TBXMLElement*)element
{
    NSMutableArray *array = [NSMutableArray array];
    TBXMLElement * f = [TBXML childElementNamed:@"lieu" parentElement:element];
    while (f !=nil)
    {
        
        Lieu* lieu = [[Lieu alloc] init];
        
        lieu.id = [TBXML valueOfAttributeNamed:@"id" forElement:f];
        lieu.nom = [TBXML textForElement:f];
        
        
        [array addObject:lieu];
        f = [TBXML nextSiblingNamed:@"lieu" searchFromElement:f];
    }
    
    return array;
}

-(id)parseMagazine:(TBXMLElement*)element
{
    Magazine *magazine;
    
    TBXMLElement * e;
    
    e = [TBXML childElementNamed:@"numero" parentElement:element];
    magazine.numero = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"periode" parentElement:element];
    magazine.periode = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"image" parentElement:element];
    magazine.image = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"url" parentElement:element];
    magazine.url = [TBXML textForElement:e];
    
    return magazine;
}

-(id)parseMarques:(TBXMLElement*)element
{
    NSMutableArray *array = [NSMutableArray array];
    TBXMLElement * f = [TBXML childElementNamed:@"marque" parentElement:element];
    while (f !=nil)
    {
        
        Marque* marque = [[Marque alloc] init];
        
        marque.id = [TBXML valueOfAttributeNamed:@"id" forElement:f];
        marque.libelle = [TBXML textForElement:f];
        
        
        [array addObject:marque];
        f = [TBXML nextSiblingNamed:@"marque" searchFromElement:f];
    }
    
    return array;
}

-(id)parseModeles:(TBXMLElement*)element
{
    NSMutableArray *array = [NSMutableArray array];
    TBXMLElement * f = [TBXML childElementNamed:@"modele" parentElement:element];
    while (f !=nil)
    {
        
        Modele* modele = [[Modele alloc] init];
        
        modele.id = [TBXML valueOfAttributeNamed:@"id" forElement:f];
        modele.libelle = [TBXML textForElement:f];
        
        
        [array addObject:modele];
        f = [TBXML nextSiblingNamed:@"modele" searchFromElement:f];
    }
    
    return array;
}

-(id)parseParametres:(TBXMLElement*)element
{
    Parametres *parametres = [[Parametres alloc]init];
    
    TBXMLElement * e;
    
    e = [TBXML childElementNamed:@"nom" parentElement:element];
    parametres.nom = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"texte_intro" parentElement:element];
    parametres.texteIntro = [TBXML textForElement:e];
    
    
    e = [TBXML childElementNamed:@"background_color_un" parentElement:element];
    parametres.backgroundColorUn =  [RBGColorManager colorFromRGBHexString:[TBXML textForElement:e]];
    
    e = [TBXML childElementNamed:@"background_color_deux" parentElement:element];
    parametres.backgroundColorDeux =  [RBGColorManager colorFromRGBHexString:[TBXML textForElement:e]];
    
    e = [TBXML childElementNamed:@"font_color_un" parentElement:element];
    parametres.fontColorUn =  [RBGColorManager colorFromRGBHexString:[TBXML textForElement:e]];
    
    e = [TBXML childElementNamed:@"font_color_deux" parentElement:element];
    parametres.fontColorDeux = [RBGColorManager colorFromRGBHexString:[TBXML textForElement:e]];
    
    e = [TBXML childElementNamed:@"maj_interval" parentElement:element];
    parametres.majInterval = [TBXML textForElement:e];
    
    //  e = [TBXML childElementNamed:@"image_start_draw9" parentElement:element];
    // parametres.imageStartDraw9 = [TBXML textForElement:e];
    
    // e = [TBXML childElementNamed:@"image_start_728x1280" parentElement:element];
    // parametres.imageStart728x1280 = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"image_start_640x1136" parentElement:element];
    parametres.imageStart640x1136 = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"image_start_640x960" parentElement:element];
    parametres.imageStart640x960 = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"image_start_32Ox480" parentElement:element];
    parametres.imageStart640x480 = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"image_fond" parentElement:element];
    parametres.imageFond = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"image_slide1" parentElement:element];
    
    NSMutableArray * images = [[NSMutableArray alloc]init];
    
    [images addObject:[TBXML textForElement:e]];
    
    e = [TBXML childElementNamed:@"image_slide2" parentElement:element];
    [images addObject:[TBXML textForElement:e]];
    
    
    e = [TBXML childElementNamed:@"image_slide3" parentElement:element];
    [images addObject:[TBXML textForElement:e]];
    
    parametres.imagesSlide = [[NSArray alloc] initWithArray:images];
    
    
    e = [TBXML childElementNamed:@"image_logo" parentElement:element];
    parametres.imageLogo = [TBXML textForElement:e];
    
    return parametres;
}

-(id)parseRegions:(TBXMLElement*)element
{
    NSMutableArray *array = [NSMutableArray array];
    TBXMLElement * f = [TBXML childElementNamed:@"region" parentElement:element];
    while (f !=nil)
    {
        
        Region* region = [[Region alloc] init];
        
        region.id = [TBXML valueOfAttributeNamed:@"id" forElement:f];
        region.nom = [TBXML textForElement:f];
        
        
        [array addObject:region];
        f = [TBXML nextSiblingNamed:@"region" searchFromElement:f];
    }
    
    return array;
}

-(id)parseServices:(TBXMLElement*)element
{
    NSMutableArray *services = [NSMutableArray array];
    TBXMLElement * f = [TBXML childElementNamed:@"service" parentElement:element];
    while (f !=nil)
    {
        [services addObject:[TBXML textForElement:f]];
        f = [TBXML nextSiblingNamed:@"service" searchFromElement:f];
    }
    return services;
}

-(id)parseTypeAnnonces:(TBXMLElement*)element
{
    NSMutableArray *array = [NSMutableArray array];
    TBXMLElement * f = [TBXML childElementNamed:@"type" parentElement:element];
    while (f !=nil)
    {
        
        TypeAnnonce* typeAnnonce = [[TypeAnnonce alloc] init];
        
        typeAnnonce.id = [TBXML valueOfAttributeNamed:@"id" forElement:f];
        typeAnnonce.nom = [TBXML textForElement:f];
        
        
        [array addObject:typeAnnonce];
        f = [TBXML nextSiblingNamed:@"type" searchFromElement:f];
    }
    
    f = [TBXML childElementNamed:@"menu" parentElement:element];
    
    do {
        
        
        
        TypeAnnonce* typeAnnonce = [[TypeAnnonce alloc] init];
        
        TBXMLElement * g = [TBXML childElementNamed:@"intitule" parentElement:f];
        typeAnnonce.intitule = [TBXML textForElement:g];
        
        g = [TBXML childElementNamed:@"nb" parentElement:f];
        typeAnnonce.nb = [TBXML textForElement:g];
        
        g = [TBXML childElementNamed:@"id" parentElement:f];
        typeAnnonce.id = [TBXML textForElement:g];
        
        g = [TBXML childElementNamed:@"urlws" parentElement:f];
        typeAnnonce.url = [TBXML textForElement:g];
        
        [array addObject:typeAnnonce];
        f = [TBXML nextSiblingNamed:@"menu" searchFromElement:f];
        
        
    } while (f != nil);
    
    
    
    
    return array;
}


-(id)parseVendeur:(TBXMLElement*)element
{
    return [self parseClient:element];
}



-(id)parseNb:(TBXMLElement*)element
{
    NBYouboat *nb = [[NBYouboat alloc] init];
    
    TBXMLElement * e;
    
    e = [TBXML childElementNamed:@"bateau" parentElement:element];
    nb.nbBateaux = [[TBXML textForElement:e] integerValue];
    
    e = [TBXML childElementNamed:@"bateaumot" parentElement:element];
    nb.nbBateauxMot = [[TBXML textForElement:e] integerValue];
    
    e = [TBXML childElementNamed:@"voile" parentElement:element];
    nb.nbVoile = [[TBXML textForElement:e] integerValue];
    
    e = [TBXML childElementNamed:@"pneuma" parentElement:element];
    nb.nbPneuma = [[TBXML textForElement:e] integerValue];
    
    e = [TBXML childElementNamed:@"moteur" parentElement:element];
    nb.nbMoteurs = [[TBXML textForElement:e] integerValue];
    
    e = [TBXML childElementNamed:@"divers" parentElement:element];
    nb.nbAccessoires = [[TBXML textForElement:e] integerValue];
    
    return nb;
}

-(id)parseVille:(TBXMLElement*)element
{
    Ville *ville = [[Ville alloc] init];
    
    TBXMLElement * e;
    
    e = [TBXML childElementNamed:@"id" parentElement:element];
    ville.id = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"nom" parentElement:element];
    ville.nom = [TBXML textForElement:e];
    
    e = [TBXML childElementNamed:@"cp" parentElement:element];
    ville.codePostal = [TBXML textForElement:e];
    
    return ville;
}


@end
